package com.yanggu.sa_token.demo_application.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
public class AuthController {

    /**
     * 登录
     */
    @PostMapping("/login")
    public String login(@RequestBody String data) {
        Long userId = 1L;
        StpUtil.login(userId);

        // 将权限数据放入缓存中
        return "登录成功";
    }

    /**
     * 登出
     */
    @PostMapping("/logout")
    public String logout() {
        StpUtil.logout();
        return "登出成功";
    }

    @SaCheckPermission("user:add")
    @SaCheckRole("admin")
    @GetMapping("/test1")
    public String test1() {
        return "test1";
    }

}
